#include <iostream>
using namespace std;

union {
    int a;
    float b;
    double c;
    char d;
}demo1;

union {
    char s[2];
    int i;
}demo2;
int main(){
    demo1.a = 128;
    printf("Demo1:%d\n", demo1.a);
    printf("Demo1:%d\n", demo1.d);

    demo2.s[0] = 0x11;
    demo2.s[1] = 0x22;
    //输出为2211是小端存储
    printf("Demo2:0x%x\n", demo2.i);

    //
    demo2.i = 0x1234;
    printf("Demo2:0x%x%x\n", demo2.s[0],demo2.s[1]);

    return 0;
}